import java.util.HashMap;
import java.util.Random;


public class EpsilonPolicy extends Policy {

	private float epsilon;
	private Random random;
	
	public EpsilonPolicy(float epsilon){
		this.epsilon = epsilon;
		this.random = new Random();
	}
	
	public Direction getPreferredDirection(HashMap<Direction, Float> qValues){
		Direction result = null;
		if(random.nextFloat() < this.epsilon){
			//random
			int index = (int) (random.nextFloat() * Direction.values().length);
			result = Direction.values()[index];
		}else{
			//epsilon greedy
			result = Direction.NORTH;
			for(Direction direction : Direction.values()){
				if(qValues.get(direction) > qValues.get(result)){
					result = direction;
				}
			}
		}
		return result;
	}
	
	public void setNewEpsilonValue(float newEpsilon){
		this.epsilon = newEpsilon;
	}
}
